package br.com.geropder.aspectos.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "SP")
public class SP implements Serializable {
	private static final long serialVersionUID = 4448862042458335448L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "sp_id")
	private long id;

	@OneToMany
	@JoinColumn(name = "regional_id")
	private Regional regional;

	@Column(name = "sp_num")
	private String numSP;

	@Column(name = "sp_nome")
	private String nomeSP;

	@Column(name = "sp_kmInicio")
	private double kmInicio;

	@Column(name = "sp_kmFinal")
	private double kmFinal;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Regional getRegional() {
		return regional;
	}

	public void setRegional(Regional regional) {
		this.regional = regional;
	}

	public String getNumSP() {
		return numSP;
	}

	public void setNumSP(String numSP) {
		this.numSP = numSP;
	}

	public String getNomeSP() {
		return nomeSP;
	}

	public void setNomeSP(String nomeSP) {
		this.nomeSP = nomeSP;
	}

	public double getKmInicio() {
		return kmInicio;
	}

	public void setKmInicio(double kmInicio) {
		this.kmInicio = kmInicio;
	}

	public double getKmFinal() {
		return kmFinal;
	}

	public void setKmFinal(double kmFinal) {
		this.kmFinal = kmFinal;
	}

	@Override
	public String toString() {
		return "SP [id=" + id + ", regional=" + regional + ", numSP=" + numSP
				+ ", nomeSP=" + nomeSP + ", kmInicio=" + kmInicio
				+ ", kmFinal=" + kmFinal + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		long temp;
		temp = Double.doubleToLongBits(kmFinal);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(kmInicio);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((nomeSP == null) ? 0 : nomeSP.hashCode());
		result = prime * result + ((numSP == null) ? 0 : numSP.hashCode());
		result = prime * result
				+ ((regional == null) ? 0 : regional.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SP other = (SP) obj;
		if (id != other.id)
			return false;
		if (Double.doubleToLongBits(kmFinal) != Double
				.doubleToLongBits(other.kmFinal))
			return false;
		if (Double.doubleToLongBits(kmInicio) != Double
				.doubleToLongBits(other.kmInicio))
			return false;
		if (nomeSP == null) {
			if (other.nomeSP != null)
				return false;
		} else if (!nomeSP.equals(other.nomeSP))
			return false;
		if (numSP == null) {
			if (other.numSP != null)
				return false;
		} else if (!numSP.equals(other.numSP))
			return false;
		if (regional == null) {
			if (other.regional != null)
				return false;
		} else if (!regional.equals(other.regional))
			return false;
		return true;
	}
}